{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1278\n",
      "143\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import json\n",
    "import datasets\n",
    "from datasets import load_dataset\n",
    "dataset = load_dataset(\"round1_test_dataset.py\",split=\"train\")\n",
    "dataset[0:40]\n",
    "sdataset = dataset.train_test_split(test_size=0.1)\n",
    "train_dataset = sdataset[\"train\"]\n",
    "val_dataset = sdataset[\"test\"]\n",
    "  \n",
    "# 将数据集以 JSON Lines 格式保存到文件，保持中文字符原样  \n",
    "with open('train_dataset.json', 'w', encoding='utf-8') as f:  \n",
    "    for example in train_dataset:  \n",
    "        json_str = json.dumps(example, ensure_ascii=False)  # 注意这里添加了 ensure_ascii=False  \n",
    "        f.write(json_str + '\\n')\n",
    "\n",
    "with open('val_dataset.json', 'w', encoding='utf-8') as f:  \n",
    "    for example in val_dataset:  \n",
    "        json_str = json.dumps(example, ensure_ascii=False)  # 注意这里添加了 ensure_ascii=False  \n",
    "        f.write(json_str + '\\n')\n",
    "\n",
    "print(len(train_dataset))\n",
    "print(len(val_dataset))\n",
    "\n",
    "# train_dataset.to_json(\"train_dataset.json\",mode=\"w\")\n",
    "# val_dataset.to_json(\"val_dataset.json\",mode=\"w\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
